﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace  智信科技物流系统
{
    public partial class Administrator : Form
    {
        public Administrator()
        {
            InitializeComponent();
        }


/************************************************tabpage1***********************************************************/
        Dao dao = new Dao();
        private void Form1_Load(object sender, EventArgs e)
        {
            if (Userini.userinfor.Rows[0]["Permissions"].ToString() == "1") //用户登录权限的判断
                {
                    tbp_managerset.Parent = null;
                }
            if (Userini.userinfor.Rows[0]["Permissions"].ToString() == "2")
                {
                    tbp_managerset.Parent = null;
                    tbp_activity.Parent = null;
                }
          
                dao.Bindalldgv(dg_admin,dg_user,dg_export,dg_activity,dg_realse);
         }

        private void Form1_Activated(object sender, EventArgs e)
        {
            dao.Bindalldgv(dg_admin, dg_user, dg_export, dg_activity, dg_realse);
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            dao.Judgeadd(tb_username,tb_password,tb_passwordag);
        }

        private void btn_delect_Click(object sender, EventArgs e)
        {
            dao.Delect(dg_admin);
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
/********************************************************************************************************************/


/******************************************************tabpage2******************************************************/
        private void tl_lb_stop_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = "update bm_User set Suspended=N'否' where UserName=N'" + dg_user.SelectedCells[0].Value.ToString() + "'";
                sqlhelper.SqlNonQuery(sql);
                MessageBox.Show("暂停成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("暂停失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);;
            }
        }

        private void tb_lb_ok_Click(object sender, EventArgs e)
        {
            try
            {
                int month, year;
                year = Convert.ToInt32(tl_tb_month.Text.ToString()) / 12;
                month = Convert.ToInt32(tl_tb_month.Text.ToString()) % 12;
                DateTime time;
                time = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
                time = time.AddMonths(month);
                time = time.AddYears(year);
                string sql = "update bm_User set Lasttime=N'" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "',expirationtime=N'" + time.ToString("yyyy-MM-dd HH:mm") + "',Suspended=N'是' where UserName=N'" + dg_user.SelectedCells[0].Value.ToString() + "'";
                sqlhelper.SqlNonQuery(sql);
                MessageBox.Show("恢复成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("恢复失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

  

        private void 最近一个月ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            operate.Export(dg_realse,true,1);
        }

        private void 导出全部ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            operate.Export(dg_export, true,0);
        }

        private void 当天的发布ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql = "select id as '信息编号',InformationType as '信息类型',InformationContent as '信息内容',UserName as '公布会员' from bm_Release where DepartureTime>='" + DateTime.Today.ToString() + "'";
            operate.BindDgv(dg_realse, sql);
            operate.Export(dg_realse, true,0);
        }

        private void tl_tb_search_TextChanged(object sender, EventArgs e)
        {
            string sql2 = "select UserName as '用户名',MobilePhone as '手机号',QQ as 'QQ号',Suspended as '是否交费',Lasttime as '上次交费时间',Expirationtime as '到期时间',RegistrationTime as '注册时间' from bm_User where Permissions=N'0' and  UserName like '%" + tl_tb_search.Text.Trim() + "%'";
            operate.BindDgv(dg_user, sql2);
        }

        private void tl_bl_delect_Click(object sender, EventArgs e)
        {
            operate.Delect(dg_user);
        }
/****************************************************************************************************************/

/***********************************************tabpage3*********************************************************/

        private void bt_add_Click(object sender, EventArgs e)
        {
            string sql = "insert into bm_Activity(theme,[Content],Time)values(N'" + tb_theme.Text.ToString() + "',N'" + rtb_information.Text.ToString() + "','" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "')";
            operate.Page3(tb_theme, rtb_information, sql);
        }

        private void bt_change_Click(object sender, EventArgs e)
        {
            string sql = "update bm_Activity set theme=N'" + tb_theme.Text.ToString() + "',[Content]=N'" + rtb_information.Text.ToString() + "' where id=" + dg_activity.SelectedCells[0].Value.ToString() + "";
            operate.Page3(tb_theme, rtb_information, sql);
        }

        private void bt_delect_Click(object sender, EventArgs e)
        {
            string sql = "delete  from bm_Activity where id=" + dg_activity.SelectedCells[0].Value.ToString() + "";
            operate.Page3(tb_theme, rtb_information, sql);
        }

        private void bt_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

/********************************************************************************************************************/
    }
}
